package reviewAlgorithms.dynamicProgramming;

public class CombinationSum4 {
    public static void main(String[] args) {
        int target = 4;
        int[] nums = {1,2,3};
        System.out.println(combinationSum4(nums,target));
    }
    public static int combinationSum4(int[] nums, int target) {
        if (nums == null || nums.length < 1 ) {
            return 0;
        }
        if (target < 1){
            return 1;
        }
        int[] dp = new int[target + 1];
        dp[0] = 1;
        for (int i = 1; i < target + 1; i++) {
            int sum = 0;
            for (int j = 0; j < nums.length; j++) {
                if (i >= nums[j]){
                    sum += dp[i - nums[j]];
                }
            }
            dp[i] = sum;
        }
        return dp[target];
    }
}
